using FireStarterModeller.BO;
using FireStarterModeller.Test.BO;
using FireStarterModeller.UI;
using Habanero.Faces.Win;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI
{
    [TestFixture]
    public class TestDirectorySelectorMapper 
    {
        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }

        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();
        }

        [Test]
        public void Test_ApplyChangesToBusinessObject()
        {
            //---------------Set up test pack-----------------
            DirectorySelectorControl control = new DirectorySelectorControl();
            DirectorySelectorMapper directorySelectorMapper = new DirectorySelectorMapper(control, "SolutionDirectory", false, new ControlFactoryWin());
            DMSolution dmSolution = new DMSolution();
            string text = TestUtilsShared.GetRandomString();
            directorySelectorMapper.BusinessObject = dmSolution;
            //---------------Assert Precondition----------------
            Assert.AreNotEqual(text, dmSolution.SolutionDirectory);
            //---------------Execute Test ----------------------
            control.FileSelectorTextBox.Text = text;
            directorySelectorMapper.ApplyChangesToBusinessObject();
            //---------------Test Result -----------------------
            Assert.AreEqual(text, dmSolution.SolutionDirectory);
        }

        [Test]
        public void Test_InternalUpdateControlValueFromBo()
        {
            //---------------Set up test pack-------------------
            DirectorySelectorControl control = new DirectorySelectorControl();
            DirectorySelectorMapper directorySelectorMapper = new DirectorySelectorMapper(control, "SolutionDirectory", false, new ControlFactoryWin());
            DMSolution dmSolution = new DMSolution();
            directorySelectorMapper.BusinessObject = dmSolution;
            string text = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------
            Assert.AreEqual("", control.FileSelectorTextBox.Text);
            //---------------Execute Test ----------------------
            dmSolution.SolutionDirectory = text;
            //---------------Test Result -----------------------
            Assert.AreEqual(text, control.FileSelectorTextBox.Text);
        }

        [Test]
        public void Test_TextChange_UpdatesBO()
        {
            //---------------Set up test pack-------------------
            DirectorySelectorControl control = new DirectorySelectorControl();
            DirectorySelectorMapper directorySelectorMapper = new DirectorySelectorMapper(control, "SolutionDirectory", false, new ControlFactoryWin());
            DMSolution dmSolution = new DMSolution();
            directorySelectorMapper.BusinessObject = dmSolution;
            string text = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------
            Assert.AreEqual("", control.FileSelectorTextBox.Text);
            //---------------Execute Test ----------------------
            control.FileSelectorTextBox.Text = text;
            //---------------Test Result -----------------------
            Assert.AreEqual(text, dmSolution.SolutionDirectory);
        }
    }
}